# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=babl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}"-git)
pkgver=0.1.78
pkgrel=1
pkgdesc="Dynamic Pixel Format Translation Library (mingw-w64)"
arch=('any')
url="http://gegl.org/babl/"
license=("GPL-3.0+" "LGPL-3.0+")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-librsvg"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' 'staticlibs')
source=(#"${_realname}"::"git+https://git.gnome.org/browse/babl"
        https://download.gimp.org/pub/babl/${pkgver%.*}/${_realname}-${pkgver}.tar.xz)
sha256sums=('17d5493633bff5585d9f375bc4df5925157cd1c70ccd7c22a635be75c172523a')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}

  meson \
    --buildtype=plain \
    -Dwith-lcms=true \
    "../${_realname}-${pkgver}"
  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"
  for pcfile in  "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|${_PRE_WIN}|${MINGW_PREFIX}|g" -i "${pcfile}"
  done
}
